﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>教务管理系统 - 教学评价</title>
    <link href="${pageContext.request.contextPath}/resources/bootstrap5/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons - 本地版本 -->
    <link href="${pageContext.request.contextPath}/resources/bootstrap-icons/1.11.3/bootstrap-icons.css" rel="stylesheet">
    <!-- Bootstrap Icons - 备用CDN -->
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
    <!-- 第二个备用CDN -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            background-color: #f5f5f5;
            margin: 0;
            padding: 0;
        }

        .header {
            background-color: #1976d2;
            color: white;
            padding: 10px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            position: fixed;
            width: 100%;
            top: 0;
            z-index: 1000;
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .header h2 {
            margin: 0;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
        }

        .header h2 img {
            height: 36px;
            margin-right: 10px;
        }

        .header .breadcrumb {
            margin: 0;
            background: transparent;
            color: white;
        }

        .header .breadcrumb a {
            color: rgba(255,255,255,0.8);
            text-decoration: none;
        }

        .header .breadcrumb a:hover {
            color: white;
        }

        .header .breadcrumb-item.active {
            color: white;
        }

        .header .breadcrumb-item+.breadcrumb-item::before {
            color: rgba(255,255,255,0.6);
        }

        /* 侧边栏样式 */
        .sidebar {
            position: fixed;
            top: 56px;
            left: 0;
            bottom: 0;
            width: 250px;
            background-color: white;
            box-shadow: 2px 0 5px rgba(0,0,0,0.1);
            overflow-y: auto;
            z-index: 100;
            padding-top: 20px;
        }

        .sidebar-menu {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .sidebar-menu > li {
            margin-bottom: 5px;
        }

        .sidebar-menu > li > a {
            display: flex;
            align-items: center;
            padding: 12px 20px;
            color: #333;
            text-decoration: none;
            transition: all 0.3s;
            border-left: 3px solid transparent;
        }

        .sidebar-menu > li > a:hover {
            background-color: #f0f0f0;
            border-left-color: #1976d2;
        }

        .sidebar-menu > li > a.active {
            background-color: #e3f2fd;
            border-left-color: #1976d2;
            color: #1976d2;
        }

        .sidebar-menu > li > a i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
            font-size: 1.1rem;
        }

        .sidebar-submenu {
            list-style: none;
            padding-left: 53px;
            max-height: 0;
            overflow: hidden;
            transition: max-height 0.3s ease;
        }

        .sidebar-menu > li.open .sidebar-submenu {
            max-height: 500px;
        }

        .sidebar-submenu > li > a {
            display: block;
            padding: 8px 0;
            color: #666;
            text-decoration: none;
            transition: all 0.3s;
        }

        .sidebar-submenu > li > a:hover {
            color: #1976d2;
        }

        .sidebar-submenu > li > a.active {
            color: #1976d2;
            font-weight: 500;
        }

        /* 内容区样式 */
        .content {
            margin-left: 250px;
            padding: 76px 20px 20px;
        }

        /* 用户名下拉菜单样式 */
        .header-user {
            display: flex;
            align-items: center;
            position: relative;
        }
        .header-user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            margin-right: 8px;
            object-fit: cover;
            background: #fff;
            cursor: pointer;
            transition: transform 0.2s;
        }
        .header-user-avatar:hover {
            transform: scale(1.1);
        }
        .header-user-name {
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }
        .user-dropdown {
            position: absolute;
            top: 100%;
            right: 0;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            min-width: 160px;
            z-index: 1001;
            opacity: 0;
            visibility: hidden;
            transform: translateY(-10px);
            transition: all 0.3s ease;
            margin-top: 8px;
        }
        .user-dropdown.show {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }
        .user-dropdown::before {
            content: '';
            position: absolute;
            top: -6px;
            right: 20px;
            width: 12px;
            height: 12px;
            background: #fff;
            transform: rotate(45deg);
            box-shadow: -2px -2px 4px rgba(0,0,0,0.1);
        }
        .user-dropdown-item {
            display: flex;
            align-items: center;
            padding: 12px 16px;
            color: #333;
            text-decoration: none;
            transition: background 0.2s;
            border-bottom: 1px solid #f0f0f0;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }
        .user-dropdown-item:last-child {
            border-bottom: none;
        }
        .user-dropdown-item:hover {
            background: #f8f9fa;
            color: #1976d2;
        }
        .user-dropdown-item i {
            margin-right: 8px;
            width: 16px;
            text-align: center;
        }

        .card {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
            margin-bottom: 20px;
            overflow: hidden;
        }

        .card-header {
            padding: 15px 20px;
            background-color: white;
            border-bottom: 1px solid #eee;
            font-weight: 600;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .card-body {
            padding: 20px;
        }

        .search-bar {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 18px;
            flex-wrap: nowrap;
        }

        .search-bar input, .search-bar select {
            border-radius: 8px;
            border: 1px solid #e3e3e3;
            padding: 6px 14px;
            font-size: 1rem;
            flex: 1;
            min-width: 150px;
        }

        .search-bar .btn {
            border-radius: 8px;
            font-size: 1rem;
            padding: 6px 18px;
            font-weight: 500;
            box-shadow: none;
            flex-shrink: 0;
        }

        .btn-primary {
            background: #1976d2;
            border: none;
        }

        .btn-primary:hover {
            background: #1565c0;
        }

        .btn-warning {
            background: #ffb300;
            color: #fff;
            border: none;
        }

        .btn-warning:hover {
            background: #ff9800;
            color: #fff;
        }

        .btn-info {
            background: #03a9f4;
            border: none;
        }

        .btn-info:hover {
            background: #0288d1;
        }

        .table {
            background: #fff;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        }

        .table thead th {
            background: #f8f9fa;
            color: #1976d2;
            font-weight: bold;
            text-align: center;
            border-bottom: 2px solid #e3e3e3;
        }

        .table tbody tr {
            transition: background 0.2s;
        }

        .table tbody tr:hover {
            background: #f1f8ff;
        }

        .table td, .table th {
            vertical-align: middle !important;
            text-align: center;
        }

        .pagination {
            justify-content: center;
            margin-top: 12px;
        }

        .pagination .page-item .page-link {
            border-radius: 6px !important;
            margin: 0 2px;
            color: #1976d2;
            border: none;
            background: #fff;
            font-weight: 500;
            transition: background 0.2s, color 0.2s;
        }

        .pagination .page-item.active .page-link {
            background: #1976d2;
            color: #fff;
        }

        .pagination .page-link:hover {
            background: #e3f2fd;
            color: #1565c0;
        }

        @media (max-width: 768px) {
            .sidebar {
                transform: translateX(-100%);
                transition: transform 0.3s;
            }

            .sidebar.active {
                transform: translateX(0);
            }

            .content {
                margin-left: 0;
            }

            .search-bar {
                flex-wrap: wrap;
            }

            .search-bar input, .search-bar select {
                min-width: 100%;
                margin-bottom: 10px;
            }
        }
    </style>
</head>
<body>
<!-- 头部导航栏 -->
<div class="header">
    <div class="header-left">
        <h2><img src="${pageContext.request.contextPath}/resources/images/logo.png" alt="Logo"> 教务管理系统</h2>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="${pageContext.request.contextPath}/teacher/home">教师首页</a></li>
                <li class="breadcrumb-item active">教学评价</li>
            </ol>
        </nav>
    </div>

    <!-- 用户名下拉菜单 -->
    <div class="header-user" id="userDropdownContainer">
        <img src="${pageContext.request.contextPath}/resources/images/baimao.png" class="header-user-avatar" alt="用户名头像" id="userAvatar">
        <span class="header-user-name" id="userName">
                <c:choose>
                    <c:when test="${not empty currentTeacher and not empty currentTeacher.user and not empty currentTeacher.user.realName}">
                        ${currentTeacher.user.realName}
                    </c:when>
                    <c:when test="${not empty sessionScope.loggedInUser and not empty sessionScope.loggedInUser.realName}">
                        ${sessionScope.loggedInUser.realName}
                    </c:when>
                    <c:when test="${not empty sessionScope.loggedInUser and not empty sessionScope.loggedInUser.username}">
                        ${sessionScope.loggedInUser.username}
                    </c:when>
                    <c:otherwise>
                        教师
                    </c:otherwise>
                </c:choose>
            </span>
        <div class="user-dropdown" id="userDropdown">
            <a href="#" class="user-dropdown-item" onclick="showProfileModal()">
                <i class="bi bi-person-circle"></i>
                个人信息
            </a>
            <a href="${pageContext.request.contextPath}/teacher/changePassword" class="user-dropdown-item">
                <i class="bi bi-key"></i>
                修改密码
            </a>
            <a href="${pageContext.request.contextPath}/user/logout" class="user-dropdown-item">
                <i class="bi bi-box-arrow-right"></i>
                退出系统
            </a>
        </div>
    </div>
</div>

<!-- 侧边栏 -->
<div class="sidebar">
    <ul class="sidebar-menu">
        <li>
            <a href="${pageContext.request.contextPath}/teacher/home">
                <i class="bi bi-house-door"></i> 教师首页
            </a>
        </li>
        <li>
            <a href="#" class="has-submenu">
                <i class="bi bi-megaphone"></i> 信息公告
            </a>
            <ul class="sidebar-submenu">
                <li><a href="${pageContext.request.contextPath}/teacher/notifications/academic">教学事务通知</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/notifications/exam">考试安排</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/notifications/classroom">教室安排</a></li>
            </ul>
        </li>
        <li>
            <a href="#" class="has-submenu">
                <i class="bi bi-book"></i> 教学管理
            </a>
            <ul class="sidebar-submenu">
                <li><a href="${pageContext.request.contextPath}/teacher/courses">我的课程</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/course-students">选课学生</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/homework">作业管理</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/grades">成绩管理</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/attendance">考勤管理</a></li>
            </ul>
        </li>
        <li class="open">
            <a href="#" class="has-submenu">
                <i class="bi bi-person-check"></i> 学生管理
            </a>
            <ul class="sidebar-submenu">
                <li><a href="${pageContext.request.contextPath}/teacher/evaluation" class="active">教学评价</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/leave">请假审批</a></li>
            </ul>
        </li>
        <li>
            <a href="${pageContext.request.contextPath}/user/logout">
                <i class="bi bi-box-arrow-right"></i> 退出系统
            </a>
        </li>
    </ul>
</div>

<!-- 主要内容区 -->
<div class="content">
    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
        <h1 class="h2">教学评价</h1>
    </div>

    <c:if test="${not empty error}">
        <div class="alert alert-danger" role="alert">
                ${error}
        </div>
    </c:if>

    <!-- 统计卡片 -->
    <div class="row mb-4">
        <div class="col-md-6">
            <div class="card text-center" style="background: linear-gradient(135deg, #1976d2 0%, #42a5f5 100%); color: white;">
                <div class="card-body">
                    <h3 class="card-title" style="font-size: 2rem; margin: 0;">${totalRecords}</h3>
                    <p class="card-text" style="margin: 0; opacity: 0.9;">评价总数</p>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="card text-center" style="background: linear-gradient(135deg, #ff7043 0%, #ff8a65 100%); color: white;">
                <div class="card-body">
                    <h3 class="card-title" style="font-size: 2rem; margin: 0;">
                        <c:set var="avgScore" value="0"/>
                        <c:set var="scoreCount" value="0"/>
                        <c:forEach var="evaluation" items="${evaluations}">
                            <c:if test="${evaluation.score != null}">
                                <c:set var="avgScore" value="${avgScore + evaluation.score}"/>
                                <c:set var="scoreCount" value="${scoreCount + 1}"/>
                            </c:if>
                        </c:forEach>
                        <c:choose>
                            <c:when test="${scoreCount > 0}">
                                <fmt:formatNumber value="${avgScore / scoreCount}" maxFractionDigits="1"/>
                            </c:when>
                            <c:otherwise>0</c:otherwise>
                        </c:choose>
                    </h3>
                    <p class="card-text" style="margin: 0; opacity: 0.9;">平均评分</p>
                </div>
            </div>
        </div>
    </div>

    <!-- 搜索区域 -->
    <div class="card">
        <div class="card-header">
            <span>教学评价查询</span>
        </div>
        <div class="card-body">
            <form method="get" action="${pageContext.request.contextPath}/teacher/evaluation">
                <div class="search-bar">
                    <select class="form-select" name="courseId">
                        <option value="">全部课程</option>
                        <c:forEach var="course" items="${teacherCourses}">
                            <option value="${course.id}" ${searchCourseId == course.id ? 'selected' : ''}>
                                    ${course.name}
                            </option>
                        </c:forEach>
                    </select>
                    <select class="form-select" name="scoreSearch">
                        <option value="">全部评分</option>
                        <option value="5" ${scoreSearch == 5 ? 'selected' : ''}>5分（优秀）</option>
                        <option value="4" ${scoreSearch == 4 ? 'selected' : ''}>4分（良好）</option>
                        <option value="3" ${scoreSearch == 3 ? 'selected' : ''}>3分（一般）</option>
                        <option value="2" ${scoreSearch == 2 ? 'selected' : ''}>2分（较差）</option>
                        <option value="1" ${scoreSearch == 1 ? 'selected' : ''}>1分（很差）</option>
                    </select>
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-search"></i> 查询
                    </button>
                    <a href="${pageContext.request.contextPath}/teacher/evaluation" class="btn btn-warning">
                        <i class="bi bi-arrow-clockwise"></i> 重置
                    </a>
                </div>
            </form>
        </div>
    </div>

    <!-- 评价记录列表 -->
    <div class="card">
        <div class="card-header">
            <span>学生评价列表</span>
        </div>
        <div class="card-body">
            <c:choose>
                <c:when test="${empty evaluations}">
                    <div class="text-center py-5">
                        <i class="bi bi-star-fill" style="font-size: 3rem; color: #ccc;"></i>
                        <p class="text-muted mt-3">暂无教学评价</p>
                    </div>
                </c:when>
                <c:otherwise>
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                            <tr>
                                <th style="width: 12%;">学号</th>
                                <th style="width: 10%;">学生姓名</th>
                                <th style="width: 15%;">课程</th>
                                <th style="width: 8%;">评分</th>
                                <th style="width: 35%;">评价内容</th>
                                <th style="width: 20%;">评价时间</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach var="evaluation" items="${evaluations}">
                                <tr>
                                    <td>${evaluation.student.studentNo}</td>
                                    <td>${evaluation.student.user.realName}</td>
                                    <td>${evaluation.course.name}</td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${evaluation.score >= 5}">
                                                <span class="badge bg-success">${evaluation.score}分</span>
                                            </c:when>
                                            <c:when test="${evaluation.score >= 4}">
                                                <span class="badge bg-info">${evaluation.score}分</span>
                                            </c:when>
                                            <c:when test="${evaluation.score >= 3}">
                                                <span class="badge bg-warning">${evaluation.score}分</span>
                                            </c:when>
                                            <c:otherwise>
                                                <span class="badge bg-danger">${evaluation.score}分</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <div style="max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;" title="${evaluation.comment}">
                                            <c:out value="${evaluation.comment}"/>
                                        </div>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty evaluation.createTime}">
                                                <fmt:formatDate value="${evaluation.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                            </c:when>
                                            <c:otherwise>
                                                <span class="text-muted">未知时间</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </c:otherwise>
            </c:choose>

            <!-- 分页 -->
            <c:if test="${totalPages != null && totalPages > 1}">
                <nav aria-label="评价记录分页">
                    <ul class="pagination justify-content-center">
                        <!-- 上一页 -->
                        <c:if test="${currentPage > 1}">
                            <li class="page-item">
                                <a class="page-link" href="?page=${currentPage - 1}&courseId=${searchCourseId}&scoreSearch=${scoreSearch}">上一页</a>
                            </li>
                        </c:if>

                        <!-- 页码 -->
                        <c:forEach begin="1" end="${totalPages}" var="i">
                            <li class="page-item ${i == currentPage ? 'active' : ''}">
                                <a class="page-link" href="?page=${i}&courseId=${searchCourseId}&scoreSearch=${scoreSearch}">${i}</a>
                            </li>
                        </c:forEach>

                        <!-- 下一页 -->
                        <c:if test="${currentPage < totalPages}">
                            <li class="page-item">
                                <a class="page-link" href="?page=${currentPage + 1}&courseId=${searchCourseId}&scoreSearch=${scoreSearch}">下一页</a>
                            </li>
                        </c:if>
                    </ul>
                </nav>
            </c:if>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/resources/bootstrap5/js/bootstrap.bundle.min.js"></script>
<script>
    // 页面加载完成后执行脚本
    document.addEventListener('DOMContentLoaded', function() {
        // 用户名下拉菜单交互
        const userDropdownContainer = document.getElementById('userDropdownContainer');
        const userDropdown = document.getElementById('userDropdown');

        if (userDropdownContainer && userDropdown) {
            userDropdownContainer.addEventListener('click', function(e) {
                e.stopPropagation();
                userDropdown.classList.toggle('show');
            });

            document.addEventListener('click', function() {
                userDropdown.classList.remove('show');
            });
        }

        // 侧边栏子菜单
        document.querySelectorAll('.has-submenu').forEach(function(item) {
            item.addEventListener('click', function(e) {
                e.preventDefault();
                this.parentNode.classList.toggle('open');
            });
        });
    });

    // 显示个人信息模态框
    function showProfileModal() {
        // 关闭用户名下拉菜单
        const dropdown = document.getElementById('userDropdown');
        dropdown.classList.remove('show');

        // 这里可以添加显示个人信息模态框的代码
        alert('个人信息功能暂未开放');
    }
</script>
</body>
</html>


